package com.ticket.api.service.Impl;

import com.ticket.api.service.TbUserInfoService;
import com.ticket.common.string.StringUtil;
import com.ticket.common.time.CommonFunction;
import com.ticket.db.dao.TbUserInfoMapper;
import com.ticket.db.entity.TblUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TbUserInfoServiceImpl implements TbUserInfoService {

    @Autowired
    TbUserInfoMapper userInfoMapper;


    @Override
    public TblUserInfo findTblUserInfoById(String uuid) {
        return userInfoMapper.findTblUserInfoById(uuid);
    }

    @Override
    public TblUserInfo findTblUserInfoByCondition(String openid) {
        return  userInfoMapper.findTblUserInfoByCondition(openid);
    }

    @Override
    public boolean insertTblUserInfo(TblUserInfo info) {
        if(info==null || info.getOpenId()==null || info.getOpenId().length()==0){return false;}
        String uuid= StringUtil.getUUID();
        String TimeData=  CommonFunction.getLocalTime14();
        info.setUuid(uuid);
        info.setCreateTime(TimeData);
        info.setLastLoginTime(TimeData);
        info.setLastUpdateUser(info.getCreateUser());
        info.setLastUpdateTime(TimeData);
     boolean fig=   userInfoMapper.insertTblUserInfo(info)==1;
        return fig;
    }

    @Override
    public Integer updateTblUserInfo(TblUserInfo info) {
        info.setLastUpdateUser(info.getCreateUser());
        info.setLastUpdateTime(CommonFunction.getLocalTime14());
        return userInfoMapper.updateTblUserInfo(info);
    }
}
